<template>
  <div class="itemList">
    <div class="top">
      <div class="play">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-bofang-copy"></use>
        </svg>
        <span>播放全部</span>
        <span>(共{{ itemlist.length }}首)</span>
      </div>
      <div class="collect">+收藏({{ subscribedCount }})</div>
    </div>
    <div class="list">
      <ul>
        <li v-for="(item, i) in itemlist" :key="i" @click="playMusic(i)">
          <span>{{ i + 1 }}</span>
          <div class="song">
            <div class="songTitle">{{ item.name }}</div>
            <span>{{ item.al.name }}</span>
          </div>
          <div class="songMenu">
            <svg class="icon" aria-hidden="true" v-if="item.mv !== 0">
              <use xlink:href="#icon-bofang-copy"></use>
            </svg>
            <svg class="icon" aria-hidden="true">
              <use xlink:href="#icon-liebiao"></use>
            </svg>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { mapMutations } from "vuex";
export default {
  props: {
    itemlist: {
      type: Array,
      default() {
        return [];
      },
    },
    subscribedCount: {
      type: Number,
      default: 0,
    },
  },
  methods: {
    playMusic(i) {
      this.UPDATEMUSIC(this.itemlist);
      this.UPDATEPLAYINDEX(i);
      //   this.$store.commit("UPDATEPLAYINDEX", i);
    },
    ...mapMutations(["UPDATEMUSIC", "UPDATEPLAYINDEX"]),
  },
};
</script>

<style scoped lang="less">
.itemList {
  background-color: #fff;
  margin-top: 50px;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  .top {
    display: flex;
    justify-content: space-between;
    padding: 8px 6px;
    .play {
      font-size: 16px;
      display: flex;
      align-items: center;
      span:nth-child(2) {
        margin: 0 2px;
      }
      span:nth-child(3) {
        font-size: 12px;
      }
      .icon {
        width: 18px;
        height: 18px;
      }
    }
    .collect {
      color: #fff;
      font-size: 14px;
      background-color: red;
      padding: 4px 20px;
      border-radius: 30px;
    }
  }

  .list {
    margin-top: 13px;
    .icon {
      width: 24px;
      height: 24px;
      fill: #ccc;
      margin: 0 8px;
    }
    ul li {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin: 12px 0;
      span {
        &:nth-child(1) {
          display: block;
          width: 30px;
          font-size: 12px;
          color: gray;
          margin-right: 6px;
        }
      }
      .song {
        font-size: 14px;
        display: flex;
        flex-direction: column;

        .songTitle {
          margin-bottom: 4px;
          width: 240px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
        span {
          font-size: 12px;
          color: #ccc;
        }
      }
      .songMenu {
        display: flex;
        justify-content: flex-end;
        flex: 1;
      }
    }
  }
}
</style>
